package com.cqie.rbac.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cqie.rbac.bo.CourseBo;
import com.cqie.rbac.entity.Course;
import com.cqie.rbac.mapper.CourseMapper;
import com.cqie.rbac.service.ICourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cqie.rbac.util.MyPageHelper;
import com.cqie.rbac.util.Result;
import com.cqie.rbac.vo.CourseVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程表 服务实现类
 * </p>
 *
 * @author 单机吧
 * @since 2021-10-11
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {

    @Override
    public List<Course> pageOfCourse(CourseBo bo) {
        if (bo.getPageNum() == null || bo.getPageSize() == null){
            bo.setPageNum(1);
            bo.setPageSize(10);
        }
        MyPageHelper.startPage(bo);
        LambdaQueryWrapper<Course> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getC_type() != null,Course::getCType,bo.getC_type());
        lqw.likeRight(StringUtils.isNotBlank(bo.getC_name()),Course::getCName,bo.getC_name());
        List<Course> courses = baseMapper.selectList(lqw);
        return courses;
    }
}
